package com.feiyun.erp.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.feiyun.erp.entity.RoleFun;
import com.feiyun.erp.service.IRoleFunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 角色权限控制器
 */
@RestController
public class RoleFunController {

    @Autowired
    private IRoleFunService roleFunService;

    @PostMapping("/role-fun")
    public ResponseEntity<String> addRoleFunction(@RequestBody RoleFun roleFun){
        roleFunService.save(roleFun);
        return ResponseEntity.ok("ok");
    }

    @DeleteMapping("/role-fun/{roleId}/{funId}")
    public ResponseEntity<String> removeRoleFunction(@PathVariable Long roleId,@PathVariable Long funId){
        roleFunService.remove(new QueryWrapper<RoleFun>().lambda()
                .eq(RoleFun::getFunId,funId).eq(RoleFun::getRoleId,roleId));
        return ResponseEntity.ok("ok");
    }
}
